package cn.lttest.user.web.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/AServlet")
public class AServlet extends HttpServlet{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		
		req.getSession().setAttribute("username", "zhangsan");
		
		Cookie cookie = new Cookie("username", "jason");
		Cookie cookie1 = new Cookie("password", "admin");
		Cookie cookie2 = new Cookie("age", "56");
		cookie.setMaxAge(60 *60 *12);
		cookie1.setMaxAge(60 *60 *12);
		cookie2.setMaxAge(60 *60 *12);
		
		resp.addCookie(cookie);
		resp.addCookie(cookie1);
		resp.addCookie(cookie2);
		
		req.getRequestDispatcher("/index.jsp").forward(req, resp);
	
	}
	
}
